package com.example.java_gobang.mapper;

import com.example.java_gobang.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserInfoMapper {
     // 插入用户
    @Insert("insert into user values(null,#{username},#{password},500,0,0)")
    Integer insert(String username,String password);
    //通过名字查找用户
    @Select("select * from user where username = #{username}")
    UserInfo selectByName(String username);
    //通过id查找用户
    @Select("select * from user where user_id = #{userId}")
    UserInfo selectById(Integer userId);
    //更新胜者信息
    @Update("update user set total_count = total_count+1,win_count = win_count+1,score=score+30" +
            " where user_id = #{userId}")
    void updateWinUser(Integer userId);
    @Update("update user set total_count = total_count+1,score=score-25" +
            " where user_id = #{userId}")
    void updateLoserUser(Integer userId);
}
